﻿using LightCAD.Core;
using LightCAD.Core.Elements;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightCAD.Runtime.Editor
{
    public enum GripShape
    {
        Rect,
        Triangle,
        Stripe
    }
    public class ControlGrip
    {
        public const float GripSize = 4;
        public static SKColor GripColor = SKColors.Blue;
        public static SKColor HoveredColor = SKColors.Red;
        public static SKColor SelectedColor = SKColors.Red;
        public string Name { get; set; }
        public int Index { get; set; }
        public GripShape Shape { get; set; }
        public Element Element { get; set; }

        public double Angle { get; set; }
        public Vector2d Position { get; set; }

        public bool IsSelected { get; set; }

        public bool IsHovered { get; set; }
        public object Data { get; set; }

        public bool IntersectWithBox(Box2d box)
        {
            var thisBox = new Box2d(new Vector2d(Position.X - GripSize, Position.Y - GripSize), GripSize * 2, GripSize * 2);
            return thisBox.IntersectWith(box);
        }
        public void Draw(SKCanvas canvas)
        {
            var wc = ElementDrawer.PointWorldToScr(Position);
            var color = GripColor;
            if (IsHovered) color = HoveredColor;
            if (IsSelected) color = SelectedColor;
            using (var pen = new SKPaint { Color = color, IsStroke = false })
            {
                canvas.DrawRect(wc.X - GripSize, wc.Y - GripSize, GripSize * 2, GripSize * 2, pen);
            }
        }
    }


}
